package classes.multithread;

import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author : DuJiabao
 * @Date : 2021/1/20 16:01
 * @Project : java_learning
 * @File : null.java
 * @Desc :
 */
public class CallableTest {
    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool();
        ArrayList<Future<String>> strings = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            strings.add(exec.submit(new CallableTask()));
        }
        for (Future<String> string : strings) {
            try {
                System.out.println(string.get());
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                exec.shutdown();
            }
        }
    }
}
